// 源插件
import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import moment from 'moment';
import router from 'umi/router';
import { StrToDate, GetDateThreeExcel } from '@/function';

// 视图插件
import {
  BackTop,
  Empty,
  Spin,
  Row,
  Col,
  Card,
  Form,
  Input,
  Select,
  Icon,
  Button,
  Dropdown,
  Menu,
  InputNumber,
  DatePicker,
  Modal,
  message,
  Badge,
  Divider,
  Steps,
  Radio,
  Upload,
} from 'antd';

// 外部组件
import UploadExcel from '@/components/Upload/UploadExcel';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';

// css OR less预编译器

/**
 *  Describe:数据连接
 *  Created by xjc on 2019/5/15
 */

@connect(({ fund, loading }) => ({
  fund,
  loading: loading.models.ruleTest,
}))
@Form.create()
class PositionRui extends PureComponent {
  componentWillMount() {}

  /**
   *  Describe:当前状态
   *  Created by xjc on 2019/5/15
   */

  state = {};

  /* @ApiModelProperty(value = "股票代码")
      private String stock;

      private Short type;

      @ApiModelProperty(value = "成本cost")
      private BigDecimal costprice;

      @ApiModelProperty(value = "在手股数 stock on hand")
      private Integer stocknumber;

      private BigDecimal lostprice;

      private String dscription;

      private Date tradedate;

      private Date addtime;

      private Short fundtype;

      private String publisher;

      private Date uploadtime;

      private Integer delflag;

      @ApiModelProperty(value = "账上可用股数")
      private Integer lastscnum;

      private BigDecimal stockprice;

      private String companyname;

      private BigDecimal param1;

      private Integer amount;

      private Integer noofshares;

      private Integer sellput;

      private Integer sellputexposure;

      private Integer aq;

      private Integer aqexposure;

      private Integer param2;

      private Integer apa2;

      private Integer dac3;

      private Integer stockonhandvalue;

      private Integer sellcall;

      private String dq;

      private Integer size;

      private String sourceperson;
  */
  upload(list, filename) {
    const { dispatch } = this.props;
    const stock = list.Data;
    let fileName = filename.replace('.xls', '');
    fileName = filename.replace('_', '');
    const thatDate = StrToDate(fileName);

    const uploadListStocks = [];
    let startFlag1 = false;
    const startFlag2 = false;
    let type = 1;
    let num = 1;
    for (let i = 0; i < stock.length - 1; i++) {
      const dataamount = [];

      if (startFlag1) {
        for (let j = 0; j < 21; j++) {
          if (stock[i][j] != null && j > 2) {
            dataamount.push(stock[i][j]);
          }
        }
        if (stock[i][0] != null && stock[i][1] != null && stock[i][0] != 'Underlying') {
          uploadListStocks.push({
            underlying: stock[i][0],
            amountPer: stock[i][1],
            amount: stock[i][2],
            type,
            data1: dataamount,
          });
        }
      }

      if (num == 1 && !startFlag1 && stock[i][0] === 'Underlying') {
        // true  和  Underlying
        startFlag1 = true;
        num++;
      }
      if (startFlag1 && stock[i][0] === 'RCN') {
        type = 2;
      }
      if (stock[i][0] === 'Option') {
        startFlag1 = false;
      }
    }
    dispatch({
      type: 'fund/RYUpload',
      payload: {
        uploadListStocks,
      },
      callback: response => {
        if (response.code == 100) {
          alert('上传成功');
        } else {
          alert('上传失败');
        }
      },
    });
  }

  /*
    STD(str) {//（日月年）
      const dateStrs = str.split("-");
      const dateMounth = this.ChooseMounth(dateStrs[1]);
      const year = parseInt("20"+dateStrs[2], 10);
      const month = dateMounth?parseInt(dateMounth, 10) - 1:null;
      const day = parseInt(dateStrs[0], 10);
      const date = new Date(year, month, day);
      return date;
    }

    ChooseMounth(str){
      switch (str) {
        case 'Jan':return 1;
        case 'Feb':return 2;
        case 'Mar':return 3;
        case 'Apr':return 4;
        case 'May':return 5;
        case 'Jun':return 6;
        case 'Jul':return 7;
        case 'Aug':return 8;
        case 'Sept':return 9;
        case 'Oct':return 10;
        case 'Nov':return 11;
        case 'Dec':return 12;
        default:return false;
      }
    }
  */

  SSBB(value) {
    // 1234
    if (value === 'Sell Put') {
      return 1;
    }
    if (value === 'Sell Call') {
      return 2;
    }
    if (value === 'Buy Put') {
      return 3;
    }
    if (value === 'Buy Call') {
      return 4;
    }
    return 0;
  }

  /**
   *  Describe:视图
   *  Created by xjc on 2019/5/15
   */

  render() {
    const {} = this.props;
    const {} = this.state;

    return (
      <PageHeaderWrapper title="瑞银上传列表">
        <Card>
          <UploadExcel upload={this.upload.bind(this)} sheets={['Data']} />
        </Card>
      </PageHeaderWrapper>
    );
  }

  componentDidMount() {
    const { dispatch } = this.props;
  }

  componentWillUnmount() {}
}

export default PositionRui;
